<?php
namespace app\api\controller;
use think\Db;
use app\admin\model\Config;
use app\common\model\School as SchoolModel;
use app\common\service\GuguService;

//用户控制器
class Member extends App
{
    
    //兑换志愿卡
    public function exchange_card()
    {
        $user_id = $this->user_id;
        $card_no = $this->request->post("card_no",'','trim');
        $card_pass = $this->request->post("card_pass",'','trim');
        if(empty($card_no) || empty($card_pass)){
            return $this->show(2001,"请填写卡号和卡密!", '');
        }
        $card = Db::name("zhiyuan_card_red")->field('id,card_id,title,card_no,pici,card_passwd,is_used,valid_days,valid_type,valid_date')->where('card_no',$card_no)->where('card_passwd',$card_pass)->find();
        if(empty($card)){
            return $this->show(2001,"卡号或卡密错误!", '');
        }
		if($card['is_used'] == 1){
			return $this->show(2001,"此卡已被使用过了!", '');
		}
		
		
        $member = Db::name("member")->where('id',$user_id)->field('id,is_upprofile,year')->find();
		if(empty($member['year']) || $member['is_upprofile']==0){
			return $this->show(2001,"请先完善信息!", '');
		}
		if($card['valid_type']==2){ //高考年份9月1
			$valid_days = $member['year'].'-09-01';
			$valid_time = strtotime($valid_days);
		}elseif($card['valid_type']==3){ //指定日期
			$valid_time = strtotime($card['valid_date']);
		}else{
			$valid_days = $card['valid_days'];
			$valid_time = strtotime("+ $valid_days day");
		}
		
		
		//$dataI = ['user_id'=>$user_id,'card_red_id'=>$card['id'],'card_id'=>$card['card_id'],'title'=>$card['title'],'card_no'=>$card['card_no'],'pici'=>$card['pici'],'card_passwd'=>$card['card_passwd'],'valid_time'=>$valid_time,'create_time'=>time()];
		
		Db::startTrans();
		Db::name("zhiyuan_card_red")->where('id',$card['id'])->update(['is_used'=>1,'user_id'=>$user_id,'use_time'=>time(),'valid_time'=>$valid_time]);
        $res = Db::name("member")->where('id',$user_id)->update(['is_vip'=>1,'valid_time'=>$valid_time]);
        if( $res !== false ){
			Db::commit();
            return $this->show(1,"操作成功", '');
        }else{
			Db::rollback();
            return $this->show(2002, "操作失败", "");
        }
    }
    
	//获取用户信息
    public function profile()
    {
        $user_id = $this->user_id;
        $info = Db::name("member")->where('id',$user_id)->field('id,username,realname,headimgurl,school,sex,year,cj_score,cj_subjects1,cj_subjects2,cj_subjects,is_upprofile,is_cj,grade,province_id,city_id,district_id,is_vip,valid_time,create_time')->find();
		if($info['is_vip']==1){
			if($info['valid_time']<time()){
				$info['is_vip'] = 0;
				$info['is_expire'] = 1;
			}else{
				$info['is_expire'] = 0;
			}
			$info['valid_time'] = date('Y-m-d',$info['valid_time']);
		}else{
			unset($info['valid_time']);
		}
		$info['create_time'] = date('Y-m-d H:i:s',$info['create_time']);
		return $this->show(1,"success", $info??[]);
    }
    
    //完善个人信息(有且只有一次)
    public function upprofile(){
        $user_id = $this->user_id;
        if($this->request->isPost()){
			$user_is_upprofile = $this->user_is_upprofile;
			if($user_is_upprofile == 1){
				return $this->show(2001,"不能修改此信息!", '');
			}
			
			$data['province_id'] = $this->request->post("province_id",0,'intval');
			$data['city_id'] = $this->request->post("city_id",0,'intval');
			$data['district_id'] = $this->request->post("district_id",0,'intval');
			$data['school'] = $this->request->post("school",'','trim');
			$data['year'] = $this->request->post("year",date('Y'),'trim');
			$data['realname'] = $this->request->post("realname",'','trim');
			$data['sex'] = $this->request->post("sex",1,'intval');
			
			if (empty($data['province_id']) || empty($data['city_id']) || empty($data['district_id'])) {
				return $this->show(2001,"请选择省市县!", '');
			}
			$province_id = Db::name('area')->where('id',$data['province_id'])->where('level',1)->value('id');
			if (empty($province_id)) {
				return $this->show(2001,"请选择正确的省份!", '');
			}
			$city_id = Db::name('area')->where('id',$data['city_id'])->where('pid',$data['province_id'])->where('level',2)->value('id');
			if (empty($city_id)) {
				return $this->show(2001,"请选择正确的城市!", '');
			}
			$district_id = Db::name('area')->where('id',$data['district_id'])->where('pid',$data['city_id'])->where('level',3)->value('id');
			if (empty($district_id)) {
				return $this->show(2001,"请选择正确的区县!", '');
			}
			if (empty($data['school']) || empty($data['year']) || empty($data['realname']) || empty($data['sex'])) {
				return $this->show(2001,"请填写完整!", '');
			}
			$data['is_upprofile'] = 1;
			$data['update_time'] = time();
			$res = Db::name("member")->where('id',$user_id)->update($data);
			if( $res !== false ){
				return $this->show(1,"success", '');
			}else{
				return $this->show(2002, "fail", "");
			} 
		}else{
            return $this->show(2001, "非法请求", "");
        }
    }
	
	//图片上传
    public function uploadimg()
    {
        $file = request()->file('file');
        if(empty($file)){
            return $this->show(2001, '请选择图片!','');
        }
        
		//dump($file);die;
        $info = $file->validate(['size'=>1024*1024*10,'ext'=>'jpg,png,jpeg'])->move( '../public/uploads');
        if($info){
			$getSaveName = str_replace("\\","/",$info->getSaveName());//把反斜杠(\)替换成斜杠(/)
            return $this->show(1,"success", ['src'=>config('app_host').'/uploads/'.$getSaveName]);
        }else{
            return $this->show(2001, $file->getError(),'');
        }
        
    } 
	
	public function edit_passwd(){
        $user_id = $this->user_id;
        if($this->request->isPost()){
			$password = $this->request->post("password",'','trim');
			if(empty($password)){
				return $this->show(2001,'情输入密码');
			}
			if(strlen($password)<6){
				return $this->show(2001,'密码最少6位');
			}
			$repassword = $this->request->post("repassword",'','trim');
			if($password != $repassword){
				return $this->show(2001,'两次密码不一致');
			}
			
			$info = Db::name("member")->where('id',$user_id)->field('id,pass_key')->find();
			if(!empty($info['pass_key'])){
				$data['pass_key'] = $info['pass_key'];
			}else{
				$data['pass_key'] = self::str_rand(10);
			}
			$data['password'] = md5($password.$data['pass_key']);
			$res = Db::name("member")->where('id',$user_id)->update($data);
			
			if( $res !== false ){
				return $this->show(1,"success", '');
			}else{
				return $this->show(2002, "fail", "");
			} 
			
		}else{
            return $this->show(2001, "非法请求", "");
        }
    }
	
	//个人资料保存
	public function save_profile(){
        $user_id = $this->user_id;
        if($this->request->isPost()){
			$city_id = $this->request->post("city_id",0,'intval');
			$district_id = $this->request->post("district_id",0,'intval');
			$school = $this->request->post("school",'','trim');
			$grade = $this->request->post("grade",'','trim');
			$realname = $this->request->post("realname",'','trim');
			$sex = $this->request->post("sex",1,'intval');
			$headimgurl = $this->request->post("headimgurl",'','trim');
			if(!empty($city_id)){
				$member_province_id = Db::name("member")->where('id',$user_id)->value('province_id');
				$province_id = Db::name("area")->where('id',$city_id)->value('pid');
				if($province_id =! $member_province_id){
					return $this->show(2001,"请选择正确的城市!", '');
				}
				$data['city_id'] = $city_id;
			}
			if(!empty($district_id)){
				$data['district_id'] = $district_id;
				if(!empty($data['city_id'])){
					$city_id = $data['city_id'];
				}else{
					$city_id = Db::name("member")->where('id',$user_id)->value('city_id');
				}
				$district_id = Db::name('area')->where('id',$data['district_id'])->where('pid',$city_id)->where('level',3)->value('id');
				if (empty($district_id)) {
					return $this->show(2001,"请选择正确的区县!", '');
				}
			}
			if(!empty($school)){
				$data['school'] = $school;
			}
			if(!empty($grade)){
				$data['grade'] = $grade;
			}
			if(!empty($realname)){
				$data['realname'] = $realname;
			}
			if(!empty($sex)){
				$data['sex'] = $sex;
			}
			if(!empty($headimgurl)){
				$data['headimgurl'] = $headimgurl;
			}
			
			$data['update_time'] = time();
			$res = Db::name("member")->where('id',$user_id)->update($data);
			if( $res !== false ){
				return $this->show(1,"success", '');
			}else{
				return $this->show(2002, "fail", "");
			} 
		}else{
            return $this->show(2001, "非法请求", "");
        }
    }
	//我收藏的资讯列表
    public function my_article_collect()
    {
        $pagesize = 10;
        $page = $this->request->get("page",0,'intval'); 
        $user_id = $this->user_id;
		
		
		$map['c.user_id'] = $user_id;
		$map['a.status'] = 1;
        $count = Db::name("article_collect")->alias('c')->join("article a",'c.article_id=a.id')->where($map)->count();
		$list = Db::name("article_collect")->alias('c')->join("article a",'c.article_id=a.id')->where($map)->field('a.id,a.title,a.writer,a.views,a.create_time')->order('id desc')
			->page($page,$pagesize)->select();  
			
		//echo Db::name("article_collect")->getlastsql();
		$list = array_map(function ($rs){
            $rs["create_time"] = !empty($rs["create_time"])?date('Y-m-d H:i',$rs["create_time"]):'';
			
            return $rs;
        }, $list);		
			
        $pages = ceil($count/10);
        $data = array('list'=>$list,'count'=>$count,'pages'=>$pages,'pagesize'=>$pagesize);
		return $this->show(1,"success", $data);
		
    }
	
	//我收藏的院校列表
    public function my_school_collect()
    {
        $pagesize = 10;
        $page = $this->request->get("page",0,'intval'); 
        $user_id = $this->user_id;
		
		
		$map['c.user_id'] = $user_id;
		$map['s.status'] = 1;
        $count = Db::name("school_collect")->alias('c')->join("school s",'c.school_id=s.id')->where($map)->count();
		$list = Db::name("school_collect")->alias('c')->join("school s",'c.school_id=s.id')->where($map)->field('s.id,s.college_name,s.cover_image,s.hot_nums,s.province_id,s.city_id,s.xian_id,s.school_suoshu,s.school_type,s.school_xingzhi')->order('id desc')
			->page($page,$pagesize)->select();  
			
		
		$suoshu_list = SchoolModel::getSuoshuList();	
		foreach($list as $k=>$v){
			$list[$k]['province'] = Db::name('area')->where('id',$v['province_id'])->value('name');
			$list[$k]['city'] = Db::name('area')->where('id',$v['city_id'])->value('name');
			$list[$k]['district'] = Db::name('area')->where('id',$v['xian_id'])->value('name');
			//$list[$k]['school_type'] = Db::name('school_type_data')->alias('d')->join('school_type t','d.type_id=t.id')->where('d.school_id',$v['id'])->value('t.title');
			$list[$k]['school_type'] = Db::name('school_type')->where('id',$v['school_type'])->value('title');
			//$list[$k]['school_xingzhi'] = Db::name('school_xingzhi_data')->alias('d')->join('school_xingzhi x','d.xingzhi_id=x.id')->where('d.school_id',$v['id'])->value('x.title');
			$list[$k]['school_xingzhi'] = Db::name('school_xingzhi')->where('id',$v['school_xingzhi'])->value('title');
			$list[$k]['school_suoshu'] = !empty($suoshu_list[$v['school_suoshu']])?$suoshu_list[$v['school_suoshu']]:'';
			$list[$k]['school_tese'] = Db::name('school_tese_data')->alias('d')->join('school_tese t','d.tese_id=t.id')->where('d.school_id',$v['id'])->column('t.title');
		}	
			
        $pages = ceil($count/10);
        $data = array('list'=>$list,'count'=>$count,'pages'=>$pages,'pagesize'=>$pagesize);
		return $this->show(1,"success", $data);
		
    }
	
	//我收藏的专业列表
    public function my_major_collect()
    {
        $pagesize = 10;
        $page = $this->request->get("page",0,'intval'); 
        $user_id = $this->user_id;
		
		
		$map['c.user_id'] = $user_id;
		$map['m.status'] = 1;
        $count = Db::name("major_collect")->alias('c')->join("major m",'c.major_id=m.id')->where($map)->count();
		$list = Db::name("major_collect")->alias('c')->join("major m",'c.major_id=m.id')->where($map)->field('m.id,m.cate_title,m.education_level,m.disciplinary_category,m.disciplinary_sub_category')->order('id desc')
			->page($page,$pagesize)->select();  
		
        $pages = ceil($count/10);
        $data = array('list'=>$list,'count'=>$count,'pages'=>$pages,'pagesize'=>$pagesize);
		return $this->show(1,"success", $data);
		
    }
	
	//我的选科列表
    public function my_choose_subject()
    {
        $pagesize = 10;
        $page = $this->request->get("page",0,'intval'); 
        $user_id = $this->user_id;
		
		
		$map['user_id'] = $user_id;
        $count = Db::name("subject_fangan")->where($map)->count();
		$list = Db::name("subject_fangan")->where($map)->order('id desc')
			->page($page,$pagesize)->select();  
		
		$list_new = [];
		foreach($list as $k=>$v){
			$list_new[$k]['province'] = Db::name('area')->where('id',$v['province_id'])->value('name');
			$list_new[$k]['major_subject_zuhe'] = $v['major_subject_zuhe'];
			$list_new[$k]['major_nums'] = count(array_filter(explode(',',$v['major_cate_ids'])));
			$list_new[$k]['school_subject_zuhe'] = $v['school_subject_zuhe'];
			$list_new[$k]['school_nums'] = count(array_filter(explode(',',$v['school_ids'])));
			$list_new[$k]['type'] = $v['type'];
			$list_new[$k]['update_time'] = date('Y-m-d H:i:s',$v['update_time']);
		}
		
        $pages = ceil($count/10);
        $data = array('list'=>$list_new,'count'=>$count,'pages'=>$pages,'pagesize'=>$pagesize);
		return $this->show(1,"success", $data);
		
    }
	
	//我的志愿列表
    public function my_zhiyuan()
    {
        $pagesize = 10;
        $page = $this->request->get("page",1,'intval'); 
        $user_id = $this->user_id;
		
		
		$map['user_id'] = $user_id;
        $count = Db::name("member_zhiyuan")->where($map)->count();
		$list = Db::name("member_zhiyuan")->field('id,title,batch,type,cj_subjects,cj_score,update_time')->where($map)->order('id desc')
			->page($page,$pagesize)->select();  
		
		$list_new = [];
		foreach($list as $k=>$v){
			$list[$k]['batch_name'] = ($v['batch']==1)?'本科':'专科';
			$list[$k]['type_name'] = ($v['type']==1)?'智能填报':'一键填报';
			$list[$k]['update_time'] = date('Y-m-d H:i:s',$v['update_time']);
			$list[$k]['export_url'] = config('app_host').'/api/news/zhiyuan_export/zid/'.$user_id.'/tid/'.$v['id'];
		}
		
        $pages = ceil($count/10);
        $data = array('list'=>$list,'count'=>$count,'pages'=>$pages,'pagesize'=>$pagesize);
		return $this->show(1,"success", $data);
		
    }
	
	
	//我的志愿列表-删除
    public function zhiyuan_del()
    {
        $user_id = $this->user_id;
        $id = $this->request->get("id",0,'intval'); 
		if(empty($id)){
			return $this->show(2001,"缺少参数id!", '');
		}
		$flag = Db::name("member_zhiyuan")->where('user_id',$user_id)->where('id',$id)->value('id');
		if(empty($flag)){
			return $this->show(2001,"未找到数据!", '');
		}
		
		$res = Db::name("member_zhiyuan")->where('user_id',$user_id)->where('id',$id)->delete();
		if( $res !== false ){
			return $this->show(1,"success", '');
		}else{
			return $this->show(2002, "fail", "");
		} 
		return $this->show(1,"success", '');
    }
	
	//个人资料保存
	public function zhiyuan_rename(){
        $user_id = $this->user_id;
        if($this->request->isPost()){
			$id = $this->request->post("id",0,'intval');
			if(empty($id)){
				return $this->show(2001,"缺少参数id!", '');
			}
			$data['title'] = $this->request->post("title",'','trim');
			if(empty($data['title'])){
				return $this->show(2001,"请填写名称!", '');
			}
			$flag = Db::name("member_zhiyuan")->where('user_id',$user_id)->where('id',$id)->value('id');
			if(empty($flag)){
				return $this->show(2001,"未找到数据!", '');
			}
			
			$data['update_time'] = time();
			$res = Db::name("member_zhiyuan")->where('user_id',$user_id)->where('id',$id)->update($data);
			if( $res !== false ){
				return $this->show(1,"success", '');
			}else{
				return $this->show(2002, "fail", "");
			} 
		}else{
            return $this->show(2001, "非法请求", "");
        }
    }
	//我的志愿列表-详情
	public function zhiyuan_detail(){
        $user_id = $this->user_id;
        
		$id = $this->request->get("id",0,'intval');
		if(empty($id)){
			return $this->show(2001,"缺少参数id!", '');
		}
		$zhiyuan_info = Db::name("member_zhiyuan")->where('user_id',$user_id)->where('id',$id)->find();
		if(empty($zhiyuan_info)){
			return $this->show(2001,"未找到数据!", '');
		}
		
		$data['title'] = $zhiyuan_info['title'];
		$data['cj_score'] = $zhiyuan_info['cj_score'];
		$data['batch'] = ($zhiyuan_info['batch']==1)?'本科':'专科';
		$data['cj_subjects'] = $zhiyuan_info['cj_subjects'];
		
		/*$zhiyuan = json_decode($zhiyuan_info['zhiyuan'],true);
		$year = date('Y',strtotime("-1 year"));
		$enrollprovince = Db::name("area")->where('id',$zhiyuan_info['province_id'])->value('name');
		$list_new = [];
		foreach($zhiyuan as $k=>$v){
			$result = GuguService::make('/metadata/ceecollegeline',['appkey'=>'UZ8X3YJWLFJWJKY28U63K8YFUTQZX4RD','pageindex'=>1,'pagesize'=>1,'searchtype'=>'PROVINCENAME','keyword'=>$enrollprovince,'schooluuid'=>$v['school_uuid'],'year'=>$year]);
			
			if($result[0] != 200){
				return $this->show(2002,$result[1]??'error', '');
			}
			$list = !empty($result[1][1])?$result[1][1][0]:[];
			
			$school_info = Db::name('school')->field('id,college_code,province,city,college_property,school_type,school_xingzhi')->where('school_uuid',$v['school_uuid'])->find();
			//$school_type = Db::name('school_type_data')->alias('d')->join('school_type t','d.type_id=t.id')->where('d.school_id',$school_info['id'])->value('t.title');
			$school_type = Db::name('school_type')->where('id',$school_info['school_type'])->value('title');
			$school_tese = Db::name('school_tese_data')->alias('d')->join('school_tese t','d.tese_id=t.id')->where('d.school_id',$school_info['id'])->column('t.title');
			$school_xingzhi = Db::name('school_xingzhi')->where('id',$school_info['school_xingzhi'])->value('title');
			$list_new[$k] = ['college_name'=>$v['college_name'],'school_code'=>$school_info['college_code'],'school_xingzhi'=>$school_xingzhi,'school_type'=>$school_type,'school_tese'=>$school_tese,'province'=>$school_info['province'],'city'=>$school_info['city'],'school_uuid'=>$v['school_uuid'],'score_min'=>$list['LowestScore']??'','weici_min'=>$list['LowestRank']??'','dengxiao_weicha'=>'','major_nums'=>count($v['data'])];
			
		}
		$data['zhiyuan'] = $list_new;*/
		$data['zhiyuan_json'] = json_decode($zhiyuan_info['zhiyuan_json'],true);
		$data['export_url'] = config('app_host').'/api/news/zhiyuan_export/zid/'.$user_id.'/tid/'.$id;
		
		return $this->show(1,"success", $data);
		
    }
	//我的志愿列表-导出
	public function zhiyuan_export(){
        $user_id = $this->user_id;
        
		$id = $this->request->get("id",0,'intval');
		if(empty($id)){
			return $this->show(2001,"缺少参数id!", '');
		}
		$zhiyuan_info = Db::name("member_zhiyuan")->where('user_id',$user_id)->where('id',$id)->find();
		if(empty($zhiyuan_info)){
			return $this->show(2001,"未找到数据!", '');
		}
		
		$title = $zhiyuan_info['title'];
		$cj_score = $zhiyuan_info['cj_score'];
		$batch = ($zhiyuan_info['batch']==1)?'本科':'专科';
		$cj_subjects = $zhiyuan_info['cj_subjects'];
		
		$arr = [];
		$zhiyuan_json = json_decode($zhiyuan_info['zhiyuan_json'],true);
		foreach($zhiyuan_json as $k=>$v){
			$title_school = $v['college_name'].'  '.$v['school_suoshu'].$v['province'].'  '.$v['school_type'].'/'.$v['school_xingzhi'].'/'.$v['city'];
			$school_line_1 = '录取人数 '.$v['plan_nums'].'  线差 '.$v['linecha'].'  最低分 '.$v['score_min'].'  最低位次 '.$v['weici_min'].'  等效位差 '.$v['dengxiao_weicha_formatted'];
			$school_line_2 = '录取人数 '.$v['plan_nums'].'  线差 '.$v['linecha_1'].'  最低分 '.$v['score_min_1'].'  最低位次 '.$v['weici_min_1'].'  等效位差 '.$v['dengxiao_weicha_formatted_1'];
			$school_line_3 = '录取人数 '.$v['plan_nums'].'  线差 '.$v['linecha_2'].'  最低分 '.$v['score_min_2'].'  最低位次 '.$v['weici_min_2'].'  等效位差 '.$v['dengxiao_weicha_formatted_2'];
			$arr[] = [$v['percentage'].'%',$title_school,count($v['majors_list']),$school_line_1,$school_line_2,$school_line_3];
			foreach($v['majors_list'] as $k1=>$v1){
				$title_marjor = $v1['major_name'].'   代码:'.$v1['major_code'];
				$marjor_line_1 = '录取人数 '.$v1['plan_nums'].'  线差 '.$v1['linecha'].'  最低分 '.$v1['score_min'].'  最低位次 '.$v1['weici_min'].'  等效位差 '.$v1['dengxiao_weicha_formatted'];
				$marjor_line_2 = '录取人数 '.$v1['plan_nums'].'  线差 '.$v1['linecha_1'].'  最低分 '.$v1['score_min_1'].'  最低位次 '.$v1['weici_min_1'].'  等效位差 '.$v1['dengxiao_weicha_formatted_1'];
				$marjor_line_3 = '录取人数 '.$v1['plan_nums'].'  线差 '.$v1['linecha_2'].'  最低分 '.$v1['score_min_2'].'  最低位次 '.$v1['weici_min_2'].'  等效位差 '.$v1['dengxiao_weicha_formatted_2'];
				$arr[] = [$v1['percentage'].'%',$title_marjor,'',$marjor_line_1,$marjor_line_2,$marjor_line_3];
			}
			
		}
		//dump($arr);die;
		
		$nowtime = time();
		$config = [
            'path' => './uploads/daochu' // xlsx文件保存路径
        ];
        $excel  = new \Vtiful\Kernel\Excel($config);
        // fileName 会自动创建一个工作表，你可以自定义该工作表名称，工作表名称为可选参数
		$excel->fileName($title.$nowtime.'.xlsx', 'sheet1');
		
		
		$format = new \Vtiful\Kernel\Format($excel->getHandle());
		$italicStyle = $format->wrap()->toResource();//自动换行
		
		// 设置列宽
		$excel->setColumn('B:B', 30); // B列宽30
		$excel->setColumn('D:D', 70); 
		$excel->setColumn('E:E', 70); 
		$excel->setColumn('F:F', 70); 
        $filePath = $excel
			->defaultFormat($italicStyle)
            ->header(['录取概率', '院校', '选择专业数量',date('Y',strtotime("-1 year")), date('Y',strtotime("-2 year")), date('Y',strtotime("-3 year"))])
            ->data($arr)
            ->output();    
	
		$data['fiel_url'] = config('app_host').'/uploads/daochu/'.$title.$nowtime.'.xlsx';
		return $this->show(1,"success", $data);
		
    }
	
	
	
	//我的志愿列表-详情-专业（暂时废弃）
	public function zhiyuan_detail_major(){
		$user_id = $this->user_id;
        
		$id = $this->request->get("id",0,'intval');
		if(empty($id)){
			return $this->show(2001,"缺少参数id!", '');
		}
		$school_uuid = $this->request->get("school_uuid",'','trim');
		if(empty($school_uuid)){
			return $this->show(2001,"缺少参数school_uuid!", '');
		}
		$zhiyuan_info = Db::name("member_zhiyuan")->where('user_id',$user_id)->where('id',$id)->find();
		if(empty($zhiyuan_info)){
			return $this->show(2001,"未找到志愿数据!", '');
		}
		$zhiyuan = json_decode($zhiyuan_info['zhiyuan'],true);
		
		$shcool = [];
		foreach($zhiyuan as $k=>$v){
			if($v['school_uuid'] == $school_uuid){
				$shcool = $v;
				break;
			}
		}
		if(empty($shcool)){
			return $this->show(2001,"未找到数据!", '');
		}
		$majors = $shcool['data'];
		if(empty($majors)){
			return $this->show(2001,"未找到专业数据!", '');
		}
		//dump($shcool);
		$enrollprovince = Db::name("area")->where('id',$zhiyuan_info['province_id'])->value('name');
		$year = date('Y',strtotime("-1 year"));
		$majors_new = [];
		foreach($majors as $km=>$vm){
			$result = GuguService::make('/metadata/ceemajorline',['appkey'=>'TZK6DJZ5LVS6V8LYDAS9WE3K4TM8ZQWZ','pageindex'=>1,'pagesize'=>100,'enrollprovince'=>$enrollprovince,'schooluuid'=>$school_uuid,'year'=>$year,'majorname'=>$vm['major_name'],'specialid'=>$vm['major_code'],'typename'=>$zhiyuan_info['typename']]);
			if($result[0] != 200){
				return $this->show(2002,$result[1]??'error', '');
			}
			$list = !empty($result[1][1])?$result[1][1]:[];
			
			foreach($list as $kl=>$vl){
				if($vl['MajorName'] == $vm['major_name']){
					$majors_new[$km] = ['major_name'=>$vl['MajorName'],'major_code'=>$vl['MajorCode'],'score_min'=>$vl['LowestScore'],'weici_min'=>$vl['LowestSection'],'dengxiao_weicha'=>'','major_code_standard'=>$vl['MajorStandardCode']];
				}
			}
				
		}
		return $this->show(1,"成功", $majors_new);
	}
	
	
	//我的订单列表
    public function my_order_list()
    {
        $pagesize = 10;
        $page = $this->request->get("page",0,'intval'); 
        $user_id = $this->user_id;
		
		
		$map['user_id'] = $user_id;
        $count = Db::name("course_order")->where($map)->count();
		$list = Db::name("course_order")->field('id,course_title as order_title,course_id,order_sn,status,order_money,type,is_base,is_zhiyuan,is_finish')->where($map)->order('id desc')
			->page($page,$pagesize)->select();  
		
		$list_new = [];
		foreach($list as $k=>$v){
			if($v['type']==1){
				$course = Db::name('course')->where('id',$v['course_id'])->field('photo,version_id')->find();
				$list[$k]['pic'] = $course['photo'];
				$list[$k]['order_desc'] = Db::name('course_version')->where('id',$course['version_id'])->value('title');
			}else{
				$zhiyuan_good = Db::name('zhiyuan_goods')->where('id',$v['course_id'])->field('photo,short_desc')->find();
				$photos = explode(',',$zhiyuan_good['photo']);
				$photos = array_filter($photos);
				$list[$k]['pic'] = !empty($photos[0])?config('app_host').$photos[0]:'';
				$list[$k]['order_desc'] = $zhiyuan_good['short_desc'];
				$list[$k]['is_ontoon'] = ($v['course_id'] == 2)?1:0;
			}
		}
		
        $pages = ceil($count/10);
        $data = array('list'=>$list,'count'=>$count,'pages'=>$pages,'pagesize'=>$pagesize);
		return $this->show(1,"success", $data);
		
    }
	
	
	//取消订单
    public function order_cancel()
    {
        $user_id = $this->user_id;
        $order_id = $this->request->get("order_id",0,'intval'); 
		if(empty($order_id)){
			return $this->show(2001,"缺少参数order_id!", '');
		}
		$course_order = Db::name("course_order")->where('user_id',$user_id)->where('id',$order_id)->field('id,status')->find();
		if(empty($course_order)){
			return $this->show(2001,"订单不存在!", '');
		}
		if($course_order['status'] == 2){
			return $this->show(2001,"订单已支付不能取消!", '');
		}
		
		$flag = Db::name("course_order")->where('user_id',$user_id)->where('id',$order_id)->delete();
		return $this->show(1,"success", '');
    }
	
	
	//我的测评列表
    public function my_cp_list()
    {
        $pagesize = 10;
        $page = $this->request->get("page",1,'intval'); 
        $user_id = $this->user_id;
		
		
		$map['uid'] = $user_id;
        //$count = Db::name("question_log")->where($map)->count();
		//$list = Db::name("question_log")->field('id,title,update_time')->where($map)->order('id desc')->page($page,$pagesize)->select();  
		$count = Db::name("ceping_log")->where($map)->count();
		$list = Db::name("ceping_log")->field('id,cp_id as ceping_id,title,update_time')->where($map)->order('id desc')->page($page,$pagesize)->select();  
		
		foreach($list as $k=>$v){
			$list[$k]['update_time'] = date('Y-m-d H:i:s',$v['update_time']);
		}
		
        $pages = ceil($count/10);
        $data = array('list'=>$list,'count'=>$count,'pages'=>$pages,'pagesize'=>$pagesize);
		return $this->show(1,"success", $data);
		
    }
	
}